﻿using System;
using System.Diagnostics;
using ALDIOrganizer;


namespace Generator
{
    public struct Shift : IComparable<Shift>
    {
        public int ID;
        public int Day;

        public int[] Candidates;

        #region number of Candidates
        public int CandidatesLeft;
        public bool NoCandidates
        {
            get
            {
                return (CandidatesLeft == 0);
            }
        }
        public int Chosen;
        #endregion
        public bool IsTaken;


        public int[] MyOverlaps; // list of Shifts which overlap with this one        
        public ShiftStub FromTo; // to nie powinna być klasa!!!
        public bool Closing
        {
            get { return FromTo.Closing; }
        }
        public bool FullShift
        {
            get { return (FromTo.Closing) && (FromTo.Opening); } // to niech będzie na stałe, bo sie nie zmienia!!
        }
        public byte length;
        public Position role;
        public bool isStoreRunners;


        public Shift DeepCopy()
        {
            var copy = new Shift
                           {
                               Candidates = Engine.ArrayDeepCopy<int>(this.Candidates),
                               CandidatesLeft = this.CandidatesLeft,
                               Chosen = this.Chosen,
                               Day = this.Day,
                               FromTo = this.FromTo,
                               ID = this.ID,
                               isStoreRunners = this.isStoreRunners,
                               length = this.length,
                               MyOverlaps = Engine.ArrayDeepCopy(MyOverlaps),
                               role = role,
                               IsTaken = IsTaken
                           };


            return copy;
        }


        #region IComparable<engShift> Members

        public int CompareTo(Shift other)
        {
            if (this.IsTaken && !other.IsTaken)
            {
                return 1;
            }
            if (other.IsTaken && !this.IsTaken)
            {
                return -1;
            }
            return this.CandidatesLeft.CompareTo(other.CandidatesLeft);
        }

        #endregion
    }
}
